home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
DIINFO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-11
|
12KB
|
378 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: diinfo.c
// Title: Data File I/O Library
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains to read and write informational fields to a data file.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <di.h>
//----------------------------------------------------------------------------
// Description: Get number of blocks in a logical file.
// Parameters: hlf Logical file handle.
// pusBlocks Number of blocks in file.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioGetBlocks(HLF hlf, PLONG plBlocks)
{
Assert(hlf >= 0 && hlf < MAX_LOGICAL_FILES);
Assert(di.logical[hlf].fUsed);
Assert(plBlocks);
Assert((di.logical[hlf].flen % (FPOS)di.logical[hlf].usBlockSize) == 0);
*plBlocks = (LONG)(di.logical[hlf].flen / (FPOS)di.logical[hlf].usBlockSize);
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Get block size of a logical file.
// Parameters: hlf Logical file handle.
// pusBlockSize Variable to receive block size.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioGetBlockSize(HLF hlf, PUSHORT pusBlockSize)
{
Assert(hlf >= 0 && hlf < MAX_LOGICAL_FILES);
Assert(di.logical[hlf].fUsed);
Assert(pusBlockSize);
*pusBlockSize = di.logical[hlf].usBlockSize;
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Get flags for a logical file.
// Parameters: hlf Logical file handle.
// pfl Variable to receive flags
// Returns:
//----------------------------------------------------------------------------
BOOL FN_E DioGetFlags(HLF hlf, PFLAG32 pfl)
{
Assert(hlf >= 0 && hlf < MAX_LOGICAL_FILES);
Assert(di.logical[hlf].fUsed);
Assert(pfl);
*pfl = di.logical[hlf].fl;
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Get # of records in a compressed isam data file.
// Parameters: hlf Logical file handle.
// pl Number of records in the file.
// Returns:
//----------------------------------------------------------------------------
BOOL FN_E DioGetRecords(HLF hlf, PLONG pl)
{
DA_COMPRESS_USER da_compress_user;
Assert(hlf >= 0 && hlf < MAX_LOGICAL_FILES);
Assert(di.logical[hlf].fUsed);
Assert(di.logical[hlf].usType == DFT_ISAM_DATA);
Assert(pl);
*pl = 0;
if (!DioGetUser(hlf, (PBYTE)&da_compress_user, sizeof(da_compress_user)))
return FALSE;
*pl = da_compress_user.lRecs;
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Get size of a logical file.
// Parameters: hlf Logical file handle.
// pfsize Variable to receive flags
// Returns:
//----------------------------------------------------------------------------
BOOL FN_E DioGetSize(HLF hlf, PFPOS pfsize)
{
Assert(hlf >= 0 && hlf < MAX_LOGICAL_FILES);
Assert(di.logical[hlf].fUsed);
Assert(pfsize);
*pfsize = di.logical[hlf].flen;
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Get user data for a logical file.
// Parameters: hlf Logical file handle.
// pb Buffer to receive data.
// cb Size of buffer
// Returns:
//----------------------------------------------------------------------------
BOOL FN_E DioGetUser(HLF hlf, PBYTE pb, SIZET cb)
{
DATADIR dir;
HPF hpf;
SIZET cDir;
Assert(hlf >= 0 && hlf < MAX_LOGICAL_FILES);
Assert(di.logical[hlf].fUsed);
Assert(pb && cb);
memset(pb, 0, cb);
hpf = di.logical[hlf].hpf;
cDir = di.logical[hlf].cDir;
if (!DioDirRead(hpf, cDir, &dir))
return FALSE;
cb = MIN(sizeof(dir.bUser), cb);
memcpy(pb, dir.bUser, cb);
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Get user data for a logical file.
// Parameters: hlf Logical file handle.
// pusVersion Variable to receive user version.
// Returns:
//----------------------------------------------------------------------------
BOOL FN_E DioGetVersion(HLF hlf, PUSHORT pusVersion)
{
DATADIR dir;
HPF hpf;
SIZET cDir;
Assert(hlf >= 0 && hlf < MAX_LOGICAL_FILES);
Assert(di.logical[hlf].fUsed);
Assert(pusVersion);
hpf = di.logical[hlf].hpf;
cDir = di.logical[hlf].cDir;
if (!DioDirRead(hpf, cDir, &dir))
return FALSE;
*pusVersion = dir.usUserVersion;
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Get flags for physical file.
// Parameters: hpf Physical file handle
// pfl Variable to receive flags
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioHeaderGetFlags(HPF hpf, PFLAG32 pfl)
{
Assert(hpf >= 0 && hpf < MAX_PHYSICAL_FILES);
Assert(di.physical[hpf].fUsed);
Assert(pfl);
*pfl = di.physical[hpf].fl;
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Get user data from file header
// Parameters: hpf Physical file handle.
// pb Data buffer
// cb Size of buffer
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioHeaderGetUser(HPF hpf, PBYTE pb, SIZET cb)
{
DATAHDR hdr;
Assert(pb && cb);
if (!DioHeaderRead(hpf, &hdr))
return FALSE;
cb = MIN(sizeof(hdr.bUser), cb);
memcpy(pb, hdr.bUser, cb);
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Get user version from header
// Parameters: hpf Physical file handle.
// pusVersion Variable to receive user version.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioHeaderGetVersion(HPF hpf, PUSHORT pusVersion)
{
DATAHDR hdr;
Assert(pusVersion);
if (!DioHeaderRead(hpf, &hdr))
return FALSE;
*pusVersion = hdr.usUserVersion;
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Set flags in file header
// Parameters: hpf Physical file handle
// fl Flags.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioHeaderSetFlags(HPF hpf, FLAG32 fl)
{
DATAHDR hdr;
if (!DioHeaderRead(hpf, &hdr))
return FALSE;
hdr.fl &= 0x0000FFFFL; // Set new flags
hdr.fl |= (fl & 0xFFFF0000L);
return DioHeaderWrite(hpf, &hdr);
}
//----------------------------------------------------------------------------
// Description: Set header user data.
// Parameters: hpf Physical file handle
// pb Data buffer
// cb Size of buffer
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioHeaderSetUser(HPF hpf, PBYTE pb, SIZET cb)
{
DATAHDR hdr;
Assert(pb && cb);
if (!DioHeaderRead(hpf, &hdr))
return FALSE;
cb = MIN(sizeof(hdr.bUser), cb);
memcpy(hdr.bUser, pb, cb);
return DioHeaderWrite(hpf, &hdr);
}
//----------------------------------------------------------------------------
// Description: Set header user version.
// Parameters: hpf Physical file handle
// usVersion User version
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioHeaderSetVersion(HPF hpf, USHORT usVersion)
{
DATAHDR hdr;
if (!DioHeaderRead(hpf, &hdr))
return FALSE;
hdr.usUserVersion = usVersion;
return DioHeaderWrite(hpf, &hdr);
}
//----------------------------------------------------------------------------
// Description: Set flags for logical file.
// Parameters: hlf Logical file handle.
// fl Flags to set.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioSetFlags(HLF hlf, FLAG32 fl)
{
DATADIR dir;
HPF hpf;
SIZET cDir;
Assert(hlf >= 0 && hlf < MAX_LOGICAL_FILES);
Assert(di.logical[hlf].fUsed);
hpf = di.logical[hlf].hpf;
cDir = di.logical[hlf].cDir;
if (!DioDirRead(hpf, cDir, &dir))
return FALSE;
dir.fl &= 0x0000FFFFL; // Set new flags
dir.fl |= (fl & 0xFFFF0000L);
return DioDirWrite(hpf, cDir, &dir);
}
//----------------------------------------------------------------------------
// Description: Set user data for a logical file.
// Parameters: hlf Logical file handle.
// pb Data buffer
// cb Size of buffer
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioSetUser(HLF hlf, PBYTE pb, SIZET cb)
{
DATADIR dir;
HPF hpf;
SIZET cDir;
Assert(hlf >= 0 && hlf < MAX_LOGICAL_FILES);
Assert(di.logical[hlf].fUsed);
Assert(pb && cb);
hpf = di.logical[hlf].hpf;
cDir = di.logical[hlf].cDir;
if (!DioDirRead(hpf, cDir, &dir))
return FALSE;
cb = MIN(sizeof(dir.bUser), cb);
memcpy(dir.bUser, pb, cb);
return DioDirWrite(hpf, cDir, &dir);
}
//----------------------------------------------------------------------------
// Description: Set user version
// Parameters: hlf Logical file handle.
// usVersion User version
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioSetVersion(HLF hlf, USHORT usVersion)
{
DATADIR dir;
HPF hpf;
SIZET cDir;
Assert(hlf >= 0 && hlf < MAX_LOGICAL_FILES);
Assert(di.logical[hlf].fUsed);
hpf = di.logical[hlf].hpf;
cDir = di.logical[hlf].cDir;
if (!DioDirRead(hpf, cDir, &dir))
return FALSE;
dir.usUserVersion = usVersion;
return DioDirWrite(hpf, cDir, &dir);
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------